package cn.bdqn.service.impl;

import cn.bdqn.bean.Topic;
import cn.bdqn.dao.TopicDao;
import cn.bdqn.dao.impl.TopicDaoImpl;
import cn.bdqn.service.TopicService;
import cn.bdqn.util.PageUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TopicServiceImpl implements TopicService {
    private TopicDao topicDao=new TopicDaoImpl();
    @Override
    public List<Topic> getAll() {
        return topicDao.getAll();
    }

    @Override
    public int del(Integer id) {
        return topicDao.del(id);
    }

    @Override
    public int updTopic(Topic topic) {
        return topicDao.updTopic(topic);
    }

    @Override
    public int add(Topic topic) {
        return topicDao.add(topic);
    }

    @Override
    public Topic getOne(Integer id) {
        return topicDao.getOne(id);
    }
    //这个业务层方法，封装了两个DAO层的操作
    @Override
    public Map<String, Object> getPage(Integer pageNo) {
        PageUtil pageUtil=new PageUtil();
        //获取数据条数，并且封装成一个对象
        Integer count=topicDao.getTotalCount();
        pageUtil.setPageNo(pageNo);
        pageUtil.setTotalCount(count);
        //获取当前页数据
        List<Topic> list=topicDao.getTopicPage(pageNo,pageUtil.getPageSize());
        //封装成一个map
        Map<String,Object> map=new HashMap<>();
        map.put("page",pageUtil);
        map.put("list",list);
        return map;
    }
}
